#!/bin/bash
trap kill_ping SIGINT SIGTERM SIGQUIT
control_dst="192.168.100.254"
compute_dst="10.8.8.254"
storage_dst="10.6.6.254"
file="/var/www/html/eth-initd.start"

function kill_ping(){
    rm -rf $file
    for i in `ps axu | grep ping |grep -v grep | grep -v color| awk -F" " '{print $2}'`
    do
       sudo kill -9 $i 
    done
    
    for i in `ps axu | grep $0 |grep -v grep | grep -v color| awk -F" " '{print $2}'`
    do
       sudo kill -9 $i
    done
}
if [[ "$1" == "stop" ]];then
    kill_ping
    exit 0
fi

echo "$1"|[ -n "`sed -n '/^[0-9][0-9]*$/p'`" ]
if [[ $? -ne 0 ]];then
    echo "The parameter must be a postive number, so exited."
    echo "Usage: $0 <Number|stop>"
    exit 1
fi

echo "$1"  > $file
if [[ $? -ne 0 ]];then
    kill_ping
fi

ping $control_dst >/dev/null 2>&1 &
ping $compute_dst >/dev/null 2>&1 &
ping $storage_dst >/dev/null 2>&1 &

echo "Broatcast multiple network network arp packets for compute $1 ..."

while [[ 1 ]]
do
    sleep 10
done
